package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.LoginDao;
import com.itheima.pojo.Member;
import com.itheima.service.LoginService;
import com.itheima.untils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import redis.clients.jedis.JedisPool;

import java.util.Date;

@Service(interfaceClass = LoginService.class)
@Transactional
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginDao loginDao;
    @Autowired
    private JedisPool jedisPool;

    @Override
    public Member log(String telephone) {
            //判断用户是否为会员
            Member member = loginDao.selectByTel(telephone);
            String password = member.getPassword();
            if (password!=null){
                String str = MD5Utils.md5(password);
                member.setPassword(str);
            }
            if (member!=null){
                return member;
            }
            //不是会员 自动完成注册
            //重新new一个member
            member = new Member();
            Date date = new Date();
            member.setPhoneNumber(telephone);
            member.setRegTime(date);
            loginDao.add(member);
            return member;
    }
}
